home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 9 / The PC-SIG Library on CD ROM - Ninth Edition.iso / 701_800 / DISK0778 / DISK0778.ZIP / A85 / LABGEN.ASM < prev    next >
Assembly Source File  |  1989-05-10  |  2KB  |  58 lines

  1. ; Some useful macros to help get you started.
  2. ;
  3. ; Please note that all of the examples use 6800 instructions and thus
  4. ; will generate error messages when assembled on other assemblers. Just
  5. ; ignore those messages (or substitute the equivalent opcode for your
  6. ; processor)--the macro ideas depicted are still valid.
  7. ;
  8.  
  9. ; Unique generated labels.
  10. ;
  11. ; Some macros will require "local" labels unique to a given expansion.
  12. ; The following macros are one way of creating them.
  13. ;
  14.  
  15. ; nlabel creates a new unique identifier (of the form l1nnnn, where n varies)
  16. ; each invocation.
  17. ;
  18. ; nlabel returns the current value of glabel, and then redefines glabel to
  19. ; the value one greater than glabel.
  20. ;
  21.          define( glabel,10000)
  22.          define( nlabel,``l'glabel`'define(`glabel',iner(glabel))')
  23. ;
  24. ; Now we have a unique label generator, but each time we call it the label
  25. ; will be different, and thus of little use for branches and jumps.
  26. ;
  27. ; We must assign this unique label string to an identifier for multiple
  28. ; uses.
  29. ;
  30.          define(local1,nlabel)
  31. local1:  nop
  32.          jmp local1
  33.          jsr local1
  34.          undefine(`local1')
  35. local1:  nop
  36. ;
  37. ; Above we define local1 to be the string generated by nlabel, use that
  38. ; string in several places, and then undefine it. Note that local1 after
  39. ; the undefine is "local1" and not a generated string. If defined locals
  40. ; are not undefined when we are done with them, we would quickly run out
  41. ; of memory space (in the macro table).
  42.  
  43. ;
  44.  
  45.         define(loop, ` define(local1,nlabel)
  46. local1:  nop
  47.          jmp local1
  48.          undefine(`local1')')
  49.  
  50.    loop
  51.    loop
  52.    loop
  53.  
  54. ; Above the macro loop is genrated three times, each time with unique local
  55. ; labels as looping targets.
  56.  
  57.  
  58.